//
//  DYJQQuanmaCell.swift
//  SheYangBigData
//
//  Created by 叁拾叁 on 2021/2/5.
//  Copyright © 2021 叁拾叁. All rights reserved.
//


import UIKit
import YYText

class DYJQQuanmaCell: SYBaseCell {
    
    var bgView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = .white
        v.layer.cornerRadius = 5.autoWidth()
        v.layer.masksToBounds = true
        return v
    }()
    
    var grayFir:UIView = {
        let v: UIView = UIView()
        v.backgroundColor = Constant.bgViewColor
        v.layer.cornerRadius = 10.autoWidth()
        v.layer.masksToBounds = true
        return v
    }()
    
    var graySec:UIView = {
        let v: UIView = UIView()
        v.backgroundColor = Constant.bgViewColor
        v.layer.cornerRadius = 10.autoWidth()
        v.layer.masksToBounds = true
        return v
    }()
    
    
    var topView: DYJQJingquInfoView = {
        let v = DYJQJingquInfoView()
        return v
    }()
    
    let title: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x333333)
        v.font = 14.autoFontSize()
        v.text = "劵码信息"
        return v
    }()
    
    let ma: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x5272FF)
        v.font = 40.autoFontSize()
        v.text = "1879 4609 4222"
        return v
    }()
    
    let shixiaoMa: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x999999)
        v.font = 15.autoFontSize()
        return v
    }()
    let yishiyong: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x999999)
        v.font = 15.autoFontSize()
        v.text = "已使用"
        return v
    }()
    
    let tip: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x999999)
        v.font = 12.autoFontSize()
        
        v.text = "请将此号码展示给商家核销"
        return v
    }()
    
    var xuxian: UIView = {
        let v = UIView(frame: CGRect(x: 15.autoWidth(), y: 171.autoWidth(), width: SCREEN_WIDTH - 60.autoWidth(), height: 1.0.autoWidth()))
//        
        return v
    }()
    
    
    func configure(_ model: RYDingdanModel) {
        yishiyong.isHidden = true
        shixiaoMa.isHidden = true
    }
    
    func configure() {
        ma.isHidden = true
        tip.isHidden = true
        shixiaoMa.snp.remakeConstraints { (make) in
            make.top.equalToSuperview().offset(208.autoWidth())
            make.left.equalToSuperview().offset(15.autoWidth())
            make.height.equalTo(15.autoWidth())
            make.bottom.equalToSuperview().offset(-25.autoWidth())
        }
    }
    
    override func initViews() {
        
        let attribtStr = NSMutableAttributedString.init(string: "1879 4609 4222", attributes: [ NSAttributedString.Key.foregroundColor: UIColor(hex: 0x999999) ?? .red, NSAttributedString.Key.strikethroughStyle: NSNumber.init(value: Int8(NSUnderlineStyle.single.rawValue))])
        let att = NSAttributedString(string: "*  ")
        attribtStr.insert(att, at: 0)
        shixiaoMa.attributedText = attribtStr
        self.backgroundColor = .clear
        addSubview(bgView)
        bgView.addSubview(topView)
        
        bgView.addSubview(title)
        bgView.addSubview(ma)
        bgView.addSubview(tip)
        bgView.addSubview(grayFir)
        bgView.addSubview(graySec)
        bgView.addSubview(xuxian)
        bgView.addSubview(shixiaoMa)
        bgView.addSubview(yishiyong)
        self.drawDashLine(lineView: xuxian, strokeColor: UIColor(hex: 0xD2D2D2), lineWidth: 1, lineLength: 1, lineSpacing: 2)
        
        topView.snp.makeConstraints { (make) in
            make.top.equalToSuperview()
            make.left.right.equalToSuperview()
        }
        title.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(185.autoWidth())
            make.left.equalToSuperview().offset(15.autoWidth())
            make.height.equalTo(15.autoWidth())
        }
        ma.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(248.autoWidth())
            make.centerX.equalToSuperview()
            make.height.equalTo(30.autoWidth())
        }
        tip.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(300.autoWidth())
            make.centerX.equalToSuperview()
            make.height.equalTo(15.autoWidth())
        }
        shixiaoMa.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(208.autoWidth())
            make.left.equalToSuperview().offset(15.autoWidth())
            make.height.equalTo(15.autoWidth())
            make.bottom.equalToSuperview().offset(-115.autoWidth())
        }
        yishiyong.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(208.autoWidth())
            make.right.equalToSuperview().offset(-15.autoWidth())
            make.height.equalTo(15.autoWidth())
        }
        
        bgView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(10.autoWidth())
            make.bottom.equalToSuperview().offset(-10.autoWidth())
            make.left.equalToSuperview()
            make.right.equalToSuperview()
        }
        
        grayFir.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(161.autoWidth())
            make.left.equalToSuperview().offset(-10.autoWidth())
            make.width.height.equalTo(20.autoWidth())
        }
        graySec.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(161.autoWidth())
            make.right.equalToSuperview().offset(10.autoWidth())
            make.width.height.equalTo(20.autoWidth())
        }
        xuxian.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(171.autoWidth())
            make.left.equalToSuperview().offset(15.autoWidth())
            make.right.equalToSuperview().offset(-15.autoWidth())
            make.height.equalTo(1.autoWidth())
        }
    }
    
    /// 绘制虚线
        /// - Parameters:
        ///   - lineView: 添加虚线的view
        ///   - strokeColor: 虚线颜色
        ///   - lineWidth: 虚线宽度
        ///   - lineLength: 每段虚线的长度
        ///   - lineSpacing: 每段虚线的间隔
        private func drawDashLine(lineView:UIView,
                                  strokeColor: UIColor,
                                  lineWidth: CGFloat = 0.5,
                                  lineLength: Int = 4,
                                  lineSpacing: Int = 4) {
            let shapeLayer = CAShapeLayer()
            shapeLayer.bounds = lineView.bounds
            shapeLayer.position = CGPoint(x: lineView.frame.size.width/2, y: lineView.frame.size.height/2)
            shapeLayer.fillColor = UIColor.blue.cgColor
            shapeLayer.strokeColor = strokeColor.cgColor
            
            shapeLayer.lineWidth = lineWidth
            shapeLayer.lineJoin = CAShapeLayerLineJoin.round
            shapeLayer.lineDashPhase = 0
            //每一段虚线长度 和 每两段虚线之间的间隔
            shapeLayer.lineDashPattern = [NSNumber(value: lineLength), NSNumber(value: lineSpacing)]
            
            let path = CGMutablePath()
            //起点
            path.move(to: CGPoint(x: lineView.frame.size.width, y: 0))

            //终点
            ///  横向 y = 0
            path.addLine(to: CGPoint(x: 0, y: 0))
            ///纵向 Y = view 的height
//            path.addLine(to: CGPoint(x: lineView.frame.width/2, y: lineView.frame.height))
            shapeLayer.path = path
            lineView.layer.addSublayer(shapeLayer)
        }
}


class DYJQJingquInfoView: SYBaseView {
    
    let locationImg: UIImageView = {
        let v = UIImageView()
        v.image = UIImage(named: "jingqu_daihexiao_title")
        return v
    }()
    
    let pic: UIImageView = {
        let v = UIImageView()
        
        return v
    }()
    
    let didian: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x333333)
        v.font = 18.autoBoldFontSize()
        v.text  = "六合龙池湖景区"
        return v
    }()
    
    
    
    let menpiaoT: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x999999)
        v.font = 15.autoFontSize()
        v.text = "门票"
        return v
    }()
    
    let shijianT: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x999999)
        v.font = 15.autoFontSize()
        v.text = "时间"
        return v
    }()
    let zongjiaT: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x999999)
        v.font = 15.autoFontSize()
        v.text = "总价"
        return v
    }()
    
    
    let menpiao: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x333333)
        v.font = 15.autoFontSize()
        
        v.text = "成人票 * 1"
        return v
    }()
    
    let shijian: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x333333)
        v.font = 15.autoFontSize()
        v.text = "2021-01-18-2021-02-19"
        return v
    }()
    
    let zongjia: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x333333)
        v.font = 15.autoFontSize()
        v.text = "￥98"
        return v
    }()
    
    override func initViews() {
        
        self.backgroundColor = .clear
        addSubview(locationImg)
        addSubview(pic)
        addSubview(didian)
        addSubview(menpiao)
        addSubview(menpiaoT)
        
        addSubview(shijian)
        addSubview(shijianT)
        addSubview(zongjia)
        addSubview(zongjiaT)
        addSubview(lineView)
        locationImg.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(15.autoWidth())
            make.left.equalToSuperview().offset(15.autoWidth())
            make.width.height.equalTo(17.autoWidth())
        }
        didian.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(15.autoWidth())
            make.left.equalToSuperview().offset(44.autoWidth())
            make.height.equalTo(17.autoWidth())
        }
        
        lineView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(48.autoWidth())
            make.left.equalToSuperview().offset(15.autoWidth())
            make.right.equalToSuperview().offset(-15.autoWidth())
            make.height.equalTo(0.5.autoWidth())
        }
        pic.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(62.autoWidth())
            make.left.equalToSuperview().offset(15.autoWidth())
            make.width.equalTo(90.autoWidth())
            make.height.equalTo(60.autoWidth())
        }
        menpiaoT.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(61.autoWidth())
            make.left.equalToSuperview().offset(131.autoWidth())
            make.height.equalTo(15.autoWidth())
        }
        shijianT.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(91.autoWidth())
            make.left.equalToSuperview().offset(131.autoWidth())
            make.height.equalTo(15.autoWidth())
        }
        zongjiaT.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(121.autoWidth())
            make.left.equalToSuperview().offset(131.autoWidth())
            make.height.equalTo(15.autoWidth())
        }
        menpiao.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(61.autoWidth())
            make.left.equalToSuperview().offset(172.autoWidth())
            make.height.equalTo(15.autoWidth())
        }
        shijian.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(91.autoWidth())
            make.left.equalToSuperview().offset(172.autoWidth())
            make.height.equalTo(15.autoWidth())
        }
        zongjia.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(121.autoWidth())
            make.left.equalToSuperview().offset(172.autoWidth())
            make.height.equalTo(15.autoWidth())
            make.bottom.equalToSuperview()
        }
    }
}
